# -*- coding: utf-8 -*-
from datetime import datetime

from google.appengine.ext import db

from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

from appengine_django.models import BaseModel as _BaseModel
#from appengine_django.models import BaseModel

import logging

class BaseModel(_BaseModel):
    id = db.IntegerProperty()

    def put(self):
        _BaseModel.put(self)
        self.id = self.key().id()
        _BaseModel.put(self)

    @classmethod
    def get_using_id(self, id):
        str_query = 'SELECT * FROM ' + self.kind() + ' WHERE id = :1'
        query = db.GqlQuery(str_query, id)
        return query.fetch(10)[0]

    @property
    def get_absolute_url(self):
        detail_name = self.__class__.__name__ + '_' + 'detail'
        return HttpResponseRedirect(reverse(detail_name.lower(), args=(self.id,)))

class MyLocation(BaseModel):
    date = db.DateTimeProperty(auto_now=True)
    geoPoint = db.GeoPtProperty()
    comment = db.TextProperty()

class TextMe(BaseModel):
    date = db.DateTimeProperty(auto_now=True)
    text = db.TextProperty()
